## climatedata <- function(data, dataset, plottype, start, end)
  
################################################################################
##
## With this software it is possible to display data such as air temperature 
## or air pressure in a line graph or histogram.
##
## parameters are as follows:
##                        
## data = character string: path to data set (no default)
## dataset = character string: "pressure", "temperature", "humidity", 
##           "precipitation", "winddirection"
## plottype = real number: 1 for line graph, 2 for histogram
## start = start time of period 'YYYY.MM.DD'
## end = end time of period 'YYYY.MM.DD'
##                        
## make shure to install the lattice.Extra package!
##
## it is necessary to replace "p_wxt" in line 81 and 93 with the suitable
## column of the dataset ("rh_wxt", "t_wxt", etc.)
##
################################################################################
##
## Copyright (C) 2011 Insa Otte, Moritz Lehmann, Simon Schlauss
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##
################################################################################ 
##
## Please be forgiving if something does not work! There are problems with 
## the histogram, we hope to fix it in the course today!!
##                        
################################################################################


## read data (filepath)
<<<<<<< local
data <- read.csv("C:/Users/Melanie/Desktop/RKurs/development/eimar-vpspph-ws2011/eimar-vpspph-ws2011/ingo/dataset_pressure.dat")
=======
data <- read.csv ("D:/Dropbox/Uni/Geographie/Umweltinformatik/R resources/kili_data/dataset_pressure.dat")
>>>>>>> other


## LatticeExtra
library(latticeExtra)


## Axis labeling - y-axis
<<<<<<< local
dataset <- ("pressure")
=======
dataset <- c("pressure")
>>>>>>> other

                        
## select plot type "line graph = 1",  "histogram = 2" 
plottype = 2

                        
## chose start time & end time | format: 'YYYY-MM-DD'
<<<<<<< local
start <- ('2011-04-14')
end <- ('2011-04-28')
=======
start <- c('2011-04-14')
end <- c('2011-04-28')
>>>>>>> other

                        
################################################################################
################################################################################                        

data$dateEAT <- as.POSIXct(data$dateEAT)


datesubset <- subset(data, dateEAT>as.POSIXct(start)&dateEAT
                     <as.POSIXct(end))
switch(plottype, 

       
## line graph       
{
  xy <- xyplot(datesubset$p_wxt ~ datesubset$dateEAT | datesubset$plotID,
             subset = datesubset$plotID != "", col = "skyblue4", 
             type = "l", layout =c(1,2), xlab = "date", ylab = dataset,
             main = "Kilimanjaro", strip = strip.custom(bg = "black", 
             par.strip.text = list(col="white", font=2)))

  xy
},
 
       
## histogram
{
  xx <- histogram(datesubset$p_wxt, 
                  type = "density", subset = datesubset$plotID != "", 
                  col = "skyblue4", layout = c(1,2), xlab = "date", 
                  ylab = dataset, main= "Kilimanjaro", 
                  strip = strip.custom(bg = "black", 
                  par.strip.text = list(col="white", font=2)))
  
  xx
  }
,)